package com.java.order.orderweb.controller;


import com.java.base.pojo.EasyUIResult;
import com.java.order.orderweb.bean.CQZGResult;
import com.java.order.orderweb.pojo.Order;
import com.java.order.orderweb.pojo.ResultMsg;
import com.java.order.orderweb.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author TriggerWu
 * @since 2018-09-13
 */
@Controller
@RequestMapping("/rest/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /*
     *  创建订单
     * 
     * @author Tigger Wu
     * @date 2018/9/20 10:00
     * @param [json]
     * @return CQZGResult
     */
    @ResponseBody
    @RequestMapping(value = "/create" , method = RequestMethod.POST)
    public CQZGResult createOrder(@RequestBody String json) {
        return orderService.createOrder(json);
    }

    /*
     *  查询订单
     *
     * @author Tigger Wu
     * @date 2018/9/21 9:54
     * @param [orderId]
     * @return com.java.order.orderweb.pojo.Order
     */
    @ResponseBody
    @RequestMapping(value = "/query/{orderId}" ,method = RequestMethod.GET)
    public Order queryOrderById(@PathVariable("orderId") String orderId) {
        return orderService.queryOrderById(orderId);
    }
    @ResponseBody
    @RequestMapping(value = "/query/{buyerNick}/{page}/{rows}",method = RequestMethod.GET)
    public EasyUIResult queryListByOrderId(@PathVariable("buyerNick") String buyerNick,@PathVariable("page") Integer page,@PathVariable("rows") Integer rows) {
        try {
            EasyUIResult easyUIResult = orderService.queryListByOrderId(buyerNick,page,rows);
            return easyUIResult;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /*
     *  修改订单支付状态
     * 
     * @author Tigger Wu
     * @date 2018/9/21 15:10
     * @param [json]
     * @return ResultMsg
     */
    @ResponseBody
    @RequestMapping(value="/changeOrderStatus",method = RequestMethod.POST)
    public ResultMsg changeOrderStatus(@RequestBody String json) throws IOException {
        return orderService.changeOrderStatus(json);
    }
}

